import 'package:json_annotation/json_annotation.dart';

import 'login_type.dart';

class LoginTypeConverter implements JsonConverter<LoginType, String> {
  const LoginTypeConverter();

  @override
  LoginType fromJson(String json) {
    switch (json) {
      case 'PHONE':
        return LoginType.PHONE;
      case 'USERNAME':
        return LoginType.USERNAME;
      case 'WECHAT':
        return LoginType.WECHAT;
      default:
        throw ArgumentError('未知类型：$json');
    }
  }

  @override
  String toJson(LoginType object) {
    return object.toString().split('.').last;
  }
}
